//
//  BottomBar.m
//  ZhihunewPaper
//
//  Created by 梅杰 on 16/7/18.
//  Copyright © 2016年 梅杰. All rights reserved.
//

#import "BottomBar.h"

@interface LPIButton : UIButton

@end

@implementation LPIButton

- (void)layoutSubviews {
    [super layoutSubviews];
    CGFloat width = self.frame.size.width;
    CGFloat height = self.frame.size.height;
    self.imageView.center = CGPointMake(width/2, height/2);
    self.titleLabel.center = CGPointMake(width/2+10.f, height/2-8.f);
    self.titleLabel.bounds = CGRectMake(0, 0, 30, 10);
    self.titleLabel.font = [UIFont systemFontOfSize:8];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
}

@end
@implementation BottomBar

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/


-(void)setWeightMethodForArrow:(void(^)(UIButton *sender))arrowBlock nextBlock : (void(^)(UIButton *sender))nextBlock voteBlock : (void(^)(UIButton *sender)) voteBlock shareBlock :(void (^)(UIButton *sender)) shareBlock commentBlock : (void (^)(UIButton *sender)) commentBlock{
    
    self.arrowBlock = arrowBlock;
    self.nextBlock = nextBlock;
    self.voteBlock = voteBlock;
    self.shareBlock = shareBlock;
    self.commentBlock = commentBlock;
    [self.arrowButton addTarget:self action:@selector(arrowButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.nextButton addTarget:self action:@selector(nextButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.voteButton addTarget:self action:@selector(voteButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.shareButton addTarget:self action:@selector(shareButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.commentButton addTarget:self action:@selector(commentButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
}
- (void) arrowButtonClicked: (UIButton *)sender{
    self.arrowBlock(sender);
}
- (void) nextButtonClicked: (UIButton *)sender{
    self.nextBlock(sender);
}- (void) voteButtonClicked: (UIButton *)sender{
    self.voteBlock(sender);
}- (void) shareButtonClicked: (UIButton *)sender{
    self.shareBlock(sender);
}- (void) commentButtonClicked: (UIButton *)sender{
    self.commentBlock(sender);
}

//- (void)awakeFromNib{
//
////    [_voteButton layoutIfNeeded];
////    [_commentButton layoutIfNeeded];
//    
////    CGRect farme = _voteButton.frame;
////    CGSize imageViewSize = _voteButton.imageView.frame.size;
////    CGRect imageR = _voteButton.imageView.frame;
////    CGRect lblSize = _voteButton.titleLabel.frame;
////    CGFloat imageX = CGRectGetMaxX(imageR);
////    CGFloat lblx = CGRectGetMinX(lblSize);
//////    CGSize labelSize = _voteButton.titleLabel.frame.size;
////    // 取得imageView最初的center
//////    CGPoint buttonCenter = _voteButton.center;
//////    _voteButton.imageView.center = buttonCenter;
////    _voteButton.titleLabel.backgroundColor = [UIColor redColor];
////    CGFloat jj = lblx - farme.size.width/2;
////    CGPoint titleLabelCenter = _voteButton.titleLabel.center;
////    UIEdgeInsets titleLabelInsets = UIEdgeInsetsMake(-imageViewSize.height/2, -1, 0, 0);
////    _voteButton.titleEdgeInsets = titleLabelInsets;
////    CGRect voteButtonFrame = _voteButton.frame;
////    _voteButton.imageView.center = CGPointMake(voteButtonFrame.size.width/2, voteButtonFrame.size.height/2);
////    _voteButton.titleLabel.center = CGPointMake(voteButtonFrame.size.width/2, voteButtonFrame.size.height/2-8.f);
////    _voteButton.titleLabel.bounds = CGRectMake(0, 0, 30, 10);
////    _voteButton.titleLabel.font = [UIFont systemFontOfSize:8];
////    _voteButton.titleLabel.textAlignment = NSTextAlignmentCenter;
////    
////    _voteButton.imageView.backgroundColor = [UIColor redColor];
////    _voteButton.titleLabel.backgroundColor = [UIColor blueColor];
////    CGRect re = _voteButton.titleLabel.frame;
////    CGRect rr = _voteButton.imageView.frame;
////    _voteButton.imageView.center = CGPointMake(100, 100);
//}

@end

